package cn.edu.seu.herald.informationplatform.dao.database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import cn.edu.seu.herald.informationplatform.bean.league.User;

public class UserDao extends DataAccessObject{
	private static UserDao daoInstance=null;	
	//Constructor of LeagueDao
	protected UserDao(){	
	}
	//Get LeagueDao instance
	public static UserDao getDao(){
		if(daoInstance==null){
			daoInstance=new UserDao();
		}
		return daoInstance;
	}
	
	public User getUserById(int id) throws SQLException{
		Connection con=getConnectionLeague();
		try {
			User user=new User();
			PreparedStatement ps=con.prepareStatement("select * from lg_user where id=? ");
			ps.setInt(1,id);
			ResultSet rs=ps.executeQuery();
			while(rs.next()){
				user.setTruename(rs.getString(4));
				user.setUsername(rs.getString(2));
			}
			closeRs(rs);
			return user;
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		}
		finally{
			closeCon(con);
			
		}
	}
}
